/**
 * Sistem Informasi Penjualan
 * @author Kelompok 1
 * Ligar Sekar Wangi
 * Tri Maryani
 * Winda Rahadyan
 * TIF/IV/A
 */

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
import java.io.*;
import javax.swing.table.DefaultTableModel;

public class Faktur extends JInternalFrame 
{
	private JPanel		jpFaktur 			= new JPanel ();

	/* Deklarasi Objek Label Ke Form Bagian Transaksi */	
	private JLabel 		lblTransaksi   		= new JLabel ("Transaksi"),
						lblRinci    		= new JLabel ("Rinci Transaksi"),
						lblNo_Faktur		= new JLabel ("No. Faktur"),
						lblKode_Pelanggan	= new JLabel ("Kode Pelanggan"), 
						lblNama_Pelanggan	= new JLabel ("Nama Pelanggan"), 
						lblTgl_Jual 		= new JLabel ("Tgl. Jual"),
						lblPembuat          = new JLabel ("Pembuat"),
						lblPenerima         = new JLabel ("Penerima"),
						lblNoSO				= new JLabel ("No SO"),   
						lblFormat_Tgl 		= new JLabel ("yyyy/mm/dd");
						
	/* Deklarasi Objek Text Ke Form Bagian Transaksi */					
	private JTextField 	txtNo_Faktur		= new JTextField (), 
						txtKode_Pelanggan	= new JTextField (), 
						txtNama_Pelanggan	= new JTextField (), 
						txtTgl_Jual         = new JTextField (),
						txtPembuat          = new JTextField (),	
						txtPenerima         = new JTextField (),	
						txtNoSO             = new JTextField ();	

	/* Deklarasi Objek Button Ke Form Bagian Transaksi */
	private JButton 	btnAddTransaksi		= new JButton ("Add"), 
						btnEditTransaksi    = new JButton ("Edit"), 
						btnDeleteTransaksi	= new JButton ("Delete"), 
						btnKosongTransaksi	= new JButton ("Bersihkan");
							
	/* Deklarasi Objek Label Ke Form Bagian Rinci Transaksi */
	private JLabel 		lblKode_Barang		= new JLabel ("Kode"), 
						lblNama_Barang		= new JLabel ("Nama Barang"), 
						lblQty_Jual			= new JLabel ("Qty Jual"), 
						lblHarga_Jual		= new JLabel ("Harga Jual"), 
						lblTotal			= new JLabel ("Total");
						
    /* Deklarasi Objek Text Ke Form Rinci Transaksi */
	private JTextField 	txtKode_Barang		= new JTextField (), 
						txtNama_Barang		= new JTextField (), 
						txtQty_Jual			= new JTextField (), 
						txtHarga_Jual		= new JTextField (), 
						txtTotal			= new JTextField ();
						
	/* Deklarasi Objek Button Ke Form Rinci Transaksi */
	private JButton 	btnAddRinci 		= new JButton ("Add Rinci"), 
						btnEditRinci		= new JButton ("Edit Rinci"), 
						btnDeleteRinci		= new JButton ("Delete Rinci"), 
						btnKosongRinci		= new JButton ("Bersihkan"), 
						btnExitRinci		= new JButton ("Exit Rinci");	


	/* Deklarasi Objek Array strJdl (Tabel) */
  	String[] strJdl = {"No.","Kode Barang","Nama","Qty Jual","Harga","Jumlah"};
	DefaultTableModel tabMode1;
	JTable tabel1 = new JTable();
	JScrollPane skrTabel1 = new JScrollPane();

	Faktur ( ) 
		{
		/* super(Judul, UkuranFrame, TombolClose, TombolMaksimum, TombolMinimum)*/
		super ("Form Faktur", false, true, false, true);
		setSize (700, 500);

		jpFaktur.setLayout (null);		

		lblTransaksi.setHorizontalAlignment(JLabel.LEFT);
		lblRinci.setHorizontalAlignment(JLabel.LEFT);
		
		/* Meletakkan Objek Di Panel */
		lblTransaksi.setBounds (15, 15, 250, 30);
		lblRinci.setBounds (15, 260, 250, 30);
		lblFormat_Tgl.setBounds (305, 140, 150, 25);
		
		lblNo_Faktur.setBounds (70, 50, 120, 25);
		lblKode_Pelanggan.setBounds (70, 80, 120, 25);
		lblNama_Pelanggan.setBounds (70, 110, 120, 25);
		lblTgl_Jual.setBounds (70, 140, 120, 25);
		lblPembuat.setBounds (70,170,120,25);
		lblPenerima.setBounds (70,200,120,25);
		lblNoSO.setBounds (70,230,120,25);
		
		lblKode_Barang.setBounds (70, 280, 50, 25);
		lblNama_Barang.setBounds (125, 280, 200, 25);
		lblQty_Jual.setBounds (330, 280, 75, 25);
		lblHarga_Jual.setBounds (410, 280, 75, 25);
		lblTotal.setBounds (330,230,120,25);
		
		txtNo_Faktur.setBounds (200, 50, 100, 25);
		txtKode_Pelanggan.setBounds (200, 80, 100, 25);
		txtNama_Pelanggan.setBounds (200, 110, 250, 25);
		txtTgl_Jual.setBounds (200, 140, 100, 25);
		txtPembuat.setBounds (200,170,100,25);
		txtPenerima.setBounds (200,200,100,25);
		txtNoSO.setBounds (200,230,100,25);
		
		txtKode_Barang.setBounds (70, 305, 50, 25);
		txtNama_Barang.setBounds (125, 305, 200, 25);
		txtQty_Jual.setBounds (330, 305, 75, 25);
		txtHarga_Jual.setBounds (410, 305, 75, 25);
	   	txtTotal.setBounds (370,230,110,25);
    	    	
		btnAddTransaksi.setBounds (570, 50, 110, 25);
		btnEditTransaksi.setBounds (570, 80, 110, 25);
		btnDeleteTransaksi.setBounds (570, 110, 110, 25);
		btnKosongTransaksi.setBounds (570, 140, 110, 25);

		btnAddRinci.setBounds (570, 220, 110, 25);
		btnEditRinci.setBounds (570, 250, 110, 25);
		btnDeleteRinci.setBounds (570, 280, 110, 25);
		btnKosongRinci.setBounds (570, 310, 110, 25);
		btnExitRinci.setBounds (570, 340, 110, 25);

		/* Instansiasi Objek Tabel */
		tabMode1 = new DefaultTableModel(null,strJdl);
		tabel1.setModel(tabMode1);
		skrTabel1.getViewport().add(tabel1);
		tabel1.setEnabled(true);
		/* Batas Scroll Tabel */
		skrTabel1.setBounds (70, 340, 470, 100);	

		/* Setting Listener Interaksi Terhadap Objek */
		focusLis fA1 = new focusLis();
		
		txtNo_Faktur.addFocusListener (fA1);
		txtKode_Pelanggan.addFocusListener (fA1);
		txtKode_Barang.addFocusListener (fA1);
	
		actionLis aL1 = new actionLis();
		
		btnAddTransaksi.addActionListener (aL1);
		btnEditTransaksi.addActionListener (aL1);
		btnDeleteTransaksi.addActionListener (aL1);
		btnKosongTransaksi.addActionListener (aL1);

		btnAddRinci.addActionListener (aL1);
		btnEditRinci.addActionListener (aL1);
		btnDeleteRinci.addActionListener (aL1);
		btnKosongRinci.addActionListener (aL1);
		btnExitRinci.addActionListener (aL1);

		/* Hanya Bilangan input Textfield Qty_Jual, Harga_Jual dan Jumlah */ 
		txtQty_Jual.addKeyListener (new KeyAdapter() {
			public void keyTyped (KeyEvent ke) {
				char c = ke.getKeyChar ();
				if (!((Character.isDigit (c) || (c == KeyEvent.VK_BACK_SPACE)))) {
					getToolkit().beep (); ke.consume ();
      			}
    		}
  		} );
  		
		txtHarga_Jual.addKeyListener (new KeyAdapter() {
			public void keyTyped (KeyEvent ke) {
				char c = ke.getKeyChar ();
				if (!((Character.isDigit (c) || (c == KeyEvent.VK_BACK_SPACE)))) {
					getToolkit().beep (); ke.consume ();
      			}
    		}
  		} );

	    /* Setting Kontrol Di Objek Panel */
		jpFaktur.add (skrTabel1);
		jpFaktur.add (lblTransaksi);	
		jpFaktur.add (lblRinci);	
		jpFaktur.add (lblFormat_Tgl);	
		jpFaktur.add (lblNo_Faktur);	
		jpFaktur.add (lblKode_Pelanggan);	
		jpFaktur.add (lblNama_Pelanggan);	
		jpFaktur.add (lblTgl_Jual);	
		jpFaktur.add (lblPembuat);
		jpFaktur.add (lblPenerima);
		jpFaktur.add (lblNoSO);
		jpFaktur.add (lblKode_Barang);	
		jpFaktur.add (lblNama_Barang);	
		jpFaktur.add (lblQty_Jual);	
		jpFaktur.add (lblHarga_Jual);	
		jpFaktur.add (lblTotal);	
		jpFaktur.add (txtNo_Faktur);	
		jpFaktur.add (txtKode_Pelanggan);	
		jpFaktur.add (txtNama_Pelanggan);	
		jpFaktur.add (txtTgl_Jual);
		jpFaktur.add (txtPembuat);
		jpFaktur.add (txtPenerima);
		jpFaktur.add (txtNoSO);	
		jpFaktur.add (txtKode_Barang);	
		jpFaktur.add (txtNama_Barang);	
		jpFaktur.add (txtQty_Jual);	
		jpFaktur.add (txtHarga_Jual);	
		jpFaktur.add (txtTotal);	
		jpFaktur.add (btnAddTransaksi);	
		jpFaktur.add (btnEditTransaksi);	
		jpFaktur.add (btnDeleteTransaksi);	
		jpFaktur.add (btnKosongTransaksi);	
		jpFaktur.add (btnAddRinci);	
		jpFaktur.add (btnEditRinci);	
		jpFaktur.add (btnDeleteRinci);	
		jpFaktur.add (btnKosongRinci);	
		jpFaktur.add (btnExitRinci);

		getContentPane().add (jpFaktur);
		AturAwal();
		setVisible (true);
	}		
  
	
	/* Metode Memeriksa Database DbInventory */
    class focusLis implements FocusListener 
    {
	    public void focusGained (FocusEvent fe) 
	    	{ 
	    	}
		public void focusLost (FocusEvent fe) 
			{
			if (fe.getSource()==txtNo_Faktur) 
				{
				if (txtNo_Faktur.getText().equals ("")) 
					{ 
					}
				else 
					{
					CariFaktur();
				    }
			    }
			if (fe.getSource()==txtKode_Pelanggan)
				{
				if (txtKode_Pelanggan.getText().equals ("")) 
					{ 
					}
				else 
					{
					CariPelanggan();
				    }
			    }
			if (fe.getSource()==txtKode_Barang) 
				{
				if (txtKode_Barang.getText().equals ("")) 
					{ 
					}
				else 
					{
					CariRinci();
				    }
			    }
		   }
    }

	/* Class Jika Klik tombol */
	class actionLis implements ActionListener{
		public void actionPerformed (ActionEvent ae) 
			{
			if (ae.getSource() == btnAddRinci) 	
				{	
				  AddRinci();	
				}
			if (ae.getSource() == btnEditRinci) 	
				{	
				  EditRinci();	
				}
			if (ae.getSource() == btnDeleteRinci) 	
				{	
				  DeleteRinci();	
				}
			if (ae.getSource() == btnKosongRinci) 	
				{	
				  KosongRinci();	
				}
			if (ae.getSource() == btnExitRinci) 	
				{	
				  AturAwal ();	
				}
			if (ae.getSource() == btnAddTransaksi) 	
				{	
				  AddTransaksi();
				}
			if (ae.getSource() == btnEditTransaksi) 	
				{	
				  EditTransaksi();	
				}
			if (ae.getSource() == btnDeleteTransaksi) 	
				{	
				  DeleteTransaksi ();	
				}
			if (ae.getSource() == btnKosongTransaksi) 	
				{	
				  AturAwal();	
				}
		}
	}
	
	/* Menonaktifkan Ketika Objek Isi Barang Di Klik */
		void AturAwal () 
		{
		/* Kosongkan Text */
		txtNo_Faktur.setText("");
		txtKode_Pelanggan.setText("");	
		txtNama_Pelanggan.setText("");		
		txtTgl_Jual.setText("");
		txtPembuat.setText("");
		txtPenerima.setText("");
		txtNoSO.setText("");
		txtTotal.setText("");	
		txtKode_Barang.setText("");	
		txtNama_Barang.setText("");	
		txtQty_Jual.setText("");	
		txtHarga_Jual.setText("");	
	
		
		/* Menonaktifkan Objek Text */
		txtNo_Faktur.setEnabled(true);
		txtKode_Pelanggan.setEnabled(false);	
		txtNama_Pelanggan.setEnabled(false);		
		txtTgl_Jual.setEnabled(false);		
		txtPembuat.setEnabled(false);
		txtPenerima.setEnabled(false);
		txtNoSO.setEnabled(false);
		txtTotal.setEnabled(false);	
		txtKode_Barang.setEnabled(false);	
		txtNama_Barang.setEnabled(false);	
		txtQty_Jual.setEnabled(false);	
		txtHarga_Jual.setEnabled(false);		
	
		
		/* Menonaktifkan Objek Button */
		btnAddTransaksi.setEnabled(false);	
		btnEditTransaksi.setEnabled(false);	
		btnDeleteTransaksi.setEnabled(false);
		btnKosongTransaksi.setEnabled(false);	
		btnAddRinci.setEnabled(false);	
		btnEditRinci.setEnabled(false);	
		btnDeleteRinci.setEnabled(false);	
		btnKosongRinci.setEnabled(false);	
		btnExitRinci.setEnabled(false);	
		
		/* Bersihkan Isi Tabel */
		DeleteTabel();
		
		/* MemFokus Ke Objek txtNo_Faktur */
		txtNo_Faktur.requestFocus ();
		
	    }
	
	/* Metoda Cari Faktur */
	void CariFaktur()
		{
		try	
			{
	   		 Connect ObjKoneksi1 = new Connect();
	   		 Connection con1 = ObjKoneksi1.OpenConnect();
	   		 Statement st1 = con1.createStatement();
	   		 String sql1 = "SELECT * FROM Faktur WHERE No_Faktur ='" + txtNo_Faktur.getText () + "'";
	   		 ResultSet rs1 = st1.executeQuery(sql1);
		     if(rs1.next())	
		     	{
			   	txtKode_Pelanggan.setText ("" + rs1.getString ("Kode_Pelanggan"));
				txtTgl_Jual.setText (""+ rs1.getString ("Tgl_Jual").substring(0,10));
				txtPembuat.setText (""+ rs1.getString ("Pembuat"));
				txtPenerima.setText (""+ rs1.getString ("Penerima"));
				txtNoSO.setText (""+ rs1.getString ("No_SO"));
				txtTotal.setText (""+ rs1.getString ("Total_Jual"));
				btnAddTransaksi.setEnabled(false);
				btnEditTransaksi.setEnabled(true);
				btnDeleteTransaksi.setEnabled(true);
				btnKosongTransaksi.setEnabled(true);
	   			rs1.close();
 	  			con1.close();
				CariPelanggan();
				tampilketabel1();
			    }
			else 
				{
				btnAddTransaksi.setEnabled(true);
				btnEditTransaksi.setEnabled(false);
				btnDeleteTransaksi.setEnabled(false);
				btnKosongTransaksi.setEnabled(true);
			}
			txtKode_Pelanggan.setEnabled(true);	
			txtTgl_Jual.setEnabled(true);	
			txtPembuat.setEnabled(true);
			txtPenerima.setEnabled(true);
			txtNoSO.setEnabled(true);	
			txtTotal.setEnabled(true);		
			txtKode_Pelanggan.requestFocus ();
		}
		catch(SQLException e) 
		{
		}
	   }
	
	/* Metode Cari Pelanggan di Tabel Pelanggan */
	void CariPelanggan()
		{
		try	{
	   		Connect ObjKoneksi1 = new Connect();
	   		Connection con1 = ObjKoneksi1.OpenConnect();
	   		Statement st1 = con1.createStatement();
	   		String sql1 = "SELECT * FROM Pelanggan WHERE Kode_Pelanggan ='" + txtKode_Pelanggan.getText () + "'";
	   		ResultSet rs1 = st1.executeQuery(sql1);
			if(rs1.next())	
			{
				txtNama_Pelanggan.setText ("" + rs1.getString ("Nama_Pelanggan"));
			}
			else 
			{
	    		JOptionPane.showMessageDialog(this, "Pelanggan Tidak Ada!!!");
			}
   			rs1.close();
   			con1.close();
		}
		catch(SQLException e) 
		{
		}
	   }

	/* Metode Cari Rinci Ke Tabel Transj */
	void CariRinci()
		{
		try	
			{
	   		Connect ObjKoneksi1 = new Connect();
	   		Connection con1 = ObjKoneksi1.OpenConnect();
	   		Statement st1 = con1.createStatement();
	   		String sql1 = "SELECT * FROM Transj WHERE No_Faktur='"+txtNo_Faktur.getText()+ "' and Kode_Barang ='" + txtKode_Barang.getText () + "'";
	   		ResultSet rs1 = st1.executeQuery(sql1);
			if(rs1.next())	
				{
				txtQty_Jual.setText ("" + rs1.getString ("Qty_Jual"));
				txtHarga_Jual.setText ("" + rs1.getString ("Harga_Jual")); 	
				btnAddRinci.setEnabled(false);
				btnEditRinci.setEnabled(true);
				btnDeleteRinci.setEnabled(true);
				btnKosongRinci.setEnabled(true);
				btnExitRinci.setEnabled(true);
			    }
			else 
				{
				btnAddRinci.setEnabled(true);
				btnEditRinci.setEnabled(false);
				btnDeleteRinci.setEnabled(false);
				btnKosongRinci.setEnabled(true);
				btnExitRinci.setEnabled(true);
			    }
	   		rs1.close();
 	  		con1.close();
			CariBarang();
			txtQty_Jual.setEnabled(true);
			txtQty_Jual.requestFocus ();
		}
		catch(SQLException e) 
		{
		}
	   }

	/* Metode Cari barang di Tabel Barang */
	void CariBarang()
		{
		try	
			{
	   		Connect ObjKoneksi1 = new Connect();
	   		Connection con1 = ObjKoneksi1.OpenConnect();
	   		Statement st1 = con1.createStatement();
	   		String sql1 = "SELECT * FROM Barang WHERE Kode_Barang ='" + txtKode_Barang.getText () + "'";
	   		ResultSet rs1 = st1.executeQuery(sql1);
			if(rs1.next())	
				{
				txtNama_Barang.setText ("" + rs1.getString ("Nama_Barang"));
				txtHarga_Jual.setText ("" + rs1.getString ("Harga_Jual"));
				}
			else 
				{
	    		JOptionPane.showMessageDialog(this, "Barang Tidak Ada!!!");
			    }
   			rs1.close();
   			con1.close();
		}
		catch(SQLException e) 
		{
		}
	   }

	/* Metode Simpan Data Ke Tabel Faktur */
	void AddTransaksi()
		{
		try	
			{
	   		Connect ObjKoneksi1 = new Connect();
	   		Connection con1 = ObjKoneksi1.OpenConnect();
	   		Statement st1 = con1.createStatement();
	   		String sql1 = "insert into Faktur(No_Faktur,Tgl_Jual,Total_Jual,Pembuat,Penerima,Kode_Pelanggan,No_SO) values('"+txtNo_Faktur.getText()+
	   			"','"+txtTgl_Jual.getText()+
	   			"','"+txtTotal.getText()+
	   			"','"+txtPembuat.getText()+		
	   			"','"+txtPenerima.getText()+	
	   			"','"+txtKode_Pelanggan.getText()+	
	   			"','"+txtNoSO.getText()+"')";
	   		int rows1 = st1.executeUpdate(sql1);
			if (rows1 == 1)
  	    		JOptionPane.showMessageDialog(this, "Data Tersimpan Ke Faktur!!!");
   			con1.close();
			nonAktifTransaksi();
		}
		catch(SQLException e) 
		{
		}
	   }

	/* Metode Edit Data Di Tabel Faktur */
	void EditTransaksi()
		{
		try	
			{
	   		Connect ObjKoneksi1 = new Connect();
	   		Connection con1 = ObjKoneksi1.OpenConnect();
	   		Statement st1 = con1.createStatement();
	   		String sql1 = "update Faktur set Kode_Pelanggan='"+txtKode_Pelanggan.getText()+
	   			"',Tgl_Jual='"+txtTgl_Jual.getText()+
	   			"',Total_Jual='"+txtTotal.getText()+
	   			"' where No_Faktur='"+txtNo_Faktur.getText()+"' ";
	   		int rows1 = st1.executeUpdate(sql1);
			if (rows1 == 1)
  	    		JOptionPane.showMessageDialog(this, "Faktur Sudah Di Edit !!!");
  	    	con1.close();
			tampilketabel1();
			nonAktifTransaksi();
		   }
		catch(SQLException e) 
		   {
		   }
	    }

	/* Metode Delete Data Di Tabel Faktur */
	void DeleteTransaksi()
		{
		try	
			{
	   		Connect ObjKoneksi1 = new Connect();
	   		Connection con1 = ObjKoneksi1.OpenConnect();
	   		Statement st1 = con1.createStatement();
	   		String sql1 = "delete from Faktur where No_Faktur='"+txtNo_Faktur.getText()+"' ";		   		
			int rows1 = st1.executeUpdate(sql1);
			if (rows1 == 1)
  	    		JOptionPane.showMessageDialog(this, "Faktur Sudah Dihapus !!!");
   			con1.close();
   			DeleteSemuaRinci();
 			AturAwal ();
		}
		catch(SQLException e) 
		{
		}
	}

	/* Metode Delete Data Di Tabel Transj */ 
	/* Sesuai Dengan No Faktur */ 
	void DeleteSemuaRinci()
		{
		try	
			{
	   		Connect ObjKoneksi1 = new Connect();
	   		Connection con1 = ObjKoneksi1.OpenConnect();
	   		Statement st1 = con1.createStatement();
	   		String sql1 = "delete from Transj where No_Faktur='"+txtNo_Faktur.getText()+"' ";		   		
			int rows1 = st1.executeUpdate(sql1);
			if (rows1 == 1)
  	    		JOptionPane.showMessageDialog(this, "Semua Penjualan Berdasarkan Faktur Dihapus!!!");
   			con1.close();
			KosongRinci();
		}
		catch(SQLException e) 
		{
		}
	   }

	/* Metode Add Data Ke Tabel Transj */
	void AddRinci()
		{
		try	
			{
	   		Connect ObjKoneksi1 = new Connect();
	   		Connection con1 = ObjKoneksi1.OpenConnect();
	   		Statement st1 = con1.createStatement();
	   		String sql1 = "insert into Transj(No_Faktur,Qty_Jual,Harga_Jual,Kode_Barang) values('"+txtNo_Faktur.getText()+
	   			"','"+txtQty_Jual.getText()+
	   			"','"+txtHarga_Jual.getText()+
	   			"','"+txtKode_Barang.getText()+"')";
	   		int rows1 = st1.executeUpdate(sql1);
	   		if (rows1 == 1)
  	    		JOptionPane.showMessageDialog(this, "Rinci Sudah Disimpan Ke Tabel Transj!!!");
  	    		String Qty_Jual=""+txtQty_Jual.getText();
  	    		String Harga_Jual=""+txtHarga_Jual.getText();
  	    	    String Jumlah =""+(Integer.parseInt(Qty_Jual) * Integer.parseInt (Harga_Jual)); 
  			    int Mtotal=0,Stotal;
  			    Stotal=Mtotal+(Integer.parseInt(Jumlah));
  			    String Total=""+txtTotal.getText();
  			    if (Integer.parseInt(Total)>0)
  			    {
  			        Stotal=Stotal+Integer.parseInt(Total);
  			        txtTotal.setText ("" + Stotal);
  			    }
  			    else
  			    {
  			    	txtTotal.setText (""+Stotal);
  			    }	
  			con1.close();
  			tampilketabel1();
  			KosongRinci();
		}
		catch(SQLException e) 
		{
		}
	   }

	/* Metode Edit Data Di Tabel Transj */
	void EditRinci()
		{
		try	
			{
	   		Connect ObjKoneksi1 = new Connect();
	   		Connection con1 = ObjKoneksi1.OpenConnect();
	   		Statement st1 = con1.createStatement();
	   		String qry;
	   		ResultSet rslt;
	   		int TotalJml; 
	   		String sql1 = "update Transj set Qty_Jual="+txtQty_Jual.getText()+" Where No_Faktur='"+txtNo_Faktur.getText()+ 
	   			"' and Kode_Barang ='" + txtKode_Barang.getText () + "'";		   		
			int rows1 = st1.executeUpdate(sql1);
  			if (rows1 == 1)
  	    		JOptionPane.showMessageDialog(this, "Rinci Sudah Di Edit Di Tabel Transj!!!");
  	    		qry="Select Sum(Qty_Jual*Harga_Jual) from Transj";
  	    		rslt=st1.executeQuery(qry);
  	    		rslt.next();
  	    		TotalJml=rslt.getInt(1);
  	    		txtTotal.setText(""+TotalJml);
  			con1.close();
			tampilketabel1();
			KosongRinci();
		}
		catch(SQLException e) 
		{
		}
	   }

	/* Metode Delete Penjualan Di Tabel Transj */
	void DeleteRinci()
		{
		try	
			{
	   		Connect ObjKoneksi1 = new Connect();
	   		Connection con1 = ObjKoneksi1.OpenConnect();
	   		Statement st1 = con1.createStatement();
	   		String sql1 = "delete from Transj Where No_Faktur='"+txtNo_Faktur.getText()+ 
	   			"' and Kode_Barang ='" + txtKode_Barang.getText () + "'";	   		
			int rows1 = st1.executeUpdate(sql1);
  			if (rows1 == 1)
  	    		JOptionPane.showMessageDialog(this, "Rinci Sudah DiHapus!!!");
  			con1.close();
			tampilketabel1();
			KosongRinci();
		}
		catch(SQLException e) 
		{
		}
	    }

	/* Metode Menonaktifkan Objek Transaksi */
	void nonAktifTransaksi()
		{
		txtKode_Barang.setEnabled(true);
		btnAddTransaksi.setEnabled(false);
		btnEditTransaksi.setEnabled(true);
		btnDeleteTransaksi.setEnabled(false);
		btnKosongTransaksi.setEnabled(false);
		txtNo_Faktur.setEnabled(true);
		txtKode_Pelanggan.setEnabled(false);	
		txtNama_Pelanggan.setEnabled(false);		
		txtTgl_Jual.setEnabled(false);	
		btnExitRinci.setEnabled(true);	
		btnKosongRinci.setEnabled(true);
		txtKode_Barang.requestFocus ();
	    }

	/* Metode Menonaktifkan Objek Rinci */
	void KosongRinci()
		{
		txtKode_Barang.setText("");
		txtNama_Barang.setText("");
		txtQty_Jual.setText("");
		txtHarga_Jual.setText("");
		txtKode_Barang.setEnabled(true);
		btnAddRinci.setEnabled(false);
		btnEditRinci.setEnabled(false);
		btnDeleteRinci.setEnabled(false);
		txtKode_Barang.requestFocus();
	}
	
 	/* Menampilkan Record Ke Tabel */
 	void tampilketabel1()
 		{
		try
			{
			DeleteTabel();
	   		Connect ObjKoneksi1 = new Connect();
	   		Connection con1 = ObjKoneksi1.OpenConnect();
	   		Statement st1 = con1.createStatement();
			String sql1 = "select Transj.kode_barang, barang.nama_Barang, transj.qty_Jual, transj.Harga_Jual from Transj, barang where Transj.No_Faktur='"+txtNo_Faktur.getText()+"' and Transj.kode_barang=barang.kode_barang" ;
			ResultSet rs1 = st1.executeQuery(sql1);
			while(rs1.next())
				{
				String Kode_Barang = rs1.getString("Kode_Barang");
				String Nama_Barang = rs1.getString("Nama_Barang");
				String Qty_Jual    = rs1.getString("Qty_Jual");
				String Harga_Jual  = rs1.getString("Harga_Jual");
				String Jumlah =""+(Integer.parseInt(Qty_Jual) * Integer.parseInt (Harga_Jual)); 
				String[] data = {"",Kode_Barang,Nama_Barang,Qty_Jual,Harga_Jual,Jumlah};
				tabMode1.addRow(data);
				resetNo();
			}
	   		rs1.close();
 	  		con1.close();
		}
		catch(Exception e){
		}
 	}
 	
 	/* mengatur kembali penomoran tabel */
	void resetNo(){ 
		int brs1 = tabMode1.getRowCount();
		for(int i=0;i<brs1;i++){
			String no1 = String.valueOf(i+1);
			tabMode1.setValueAt(no1+".",i,0);
		}
	}
	
	/* mengosongkan isi tabel */
	void DeleteTabel()
		{
		int brs1 = tabMode1.getRowCount();
		for(int i=0;i<brs1;i++)
			{
			tabMode1.removeRow(0);
	    	}
	    }
	
}